package com.landscope.issue.controller.api;

import cn.hutool.core.date.DateUtil;
import com.landscope.issue.controller.api.dto.MainIndexDto;
import com.landscope.issue.controller.api.dto.ProjectListDto;
import com.landscope.issue.controller.api.dto.SimProjectListDto;
import com.landscope.issue.controller.api.param.LoginParam;
import com.landscope.issue.controller.api.param.MainIndexParam;
import com.landscope.issue.controller.base.ResponseResult;
import com.landscope.issue.service.ApiMainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author qzp
 * @version v1.0
 * @date 2021/8/2 15:22
 **/
@RequestMapping("api/m/main")
@RestController
@Api(tags = "2.首页")
@CrossOrigin
public class ApiMainController {

    @Resource
    private ApiMainService apiMainService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", dataType = "String")
    })
    @ApiOperation(value = "2.1 获取首页数据", notes = "获取首页数据")
    @PostMapping("/index")
    public ResponseResult<MainIndexDto> index(@RequestBody MainIndexParam param) {
        return apiMainService.index(param);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", dataType = "String")
    })
    @ApiOperation(value = "2.2 获取项目列表", notes = "获取项目列表")
    @PostMapping("/projectList")
    public ResponseResult<List<SimProjectListDto>> projectList(@RequestBody LoginParam param) {
        return apiMainService.projectList(param);
    }

    public static void main(String[] strs) {
//        Calendar // 将时间进行周一到周日补全
//                calendar = Calendar.getInstance();
//        Date date = DateUtil.parseDateTime("2021-09-30 00:00:00");
//        calendar.setTime(date);
//        // 将结束时间设置为周日
//        if (calendar.get(Calendar.DAY_OF_WEEK) == 1) {
//            calendar.add(Calendar.WEEK_OF_MONTH, -1);
//        }
//        calendar.set(Calendar.DAY_OF_WEEK, 2);
//        System.out.println(DateUtil.formatDateTime(calendar.getTime()));
//
//        calendar.add(Calendar.WEEK_OF_MONTH, 1);
//        calendar.set(Calendar.DAY_OF_WEEK, 1);
//        System.out.println(DateUtil.formatDateTime(calendar.getTime()));

        System.out.println(DateUtil.format(new Date(),"yyyy-M-d"));
    }
}
